function trades = trading_strategy(all_ret_predicted)

open_position = 0;
trades = [];

nb_ret = size(all_ret_predicted,1);
for j = 1:nb_ret
    s = sign(all_ret_predicted(j));
    if (s > 0) && (j <nb_ret) % buy signal and not yet the last day
        if (~open_position)
            % open position
            trades = vertcat(trades, [1 j]);
            open_position = 1;
        end
    elseif (s < 0) || (j == nb_ret) % sell signal
        if (open_position)
            % close position
            trades = vertcat(trades, [-1 j]);
            open_position = 0;
        end
    end   
end
end    


